<template>
    <Form ref="formData" :model="formData" :label-width="80" disabled>
        <Row>
            <Col span="12">
                <FormItem label="联系人">
                    <Input v-model="formData.contactName"/>
                </FormItem>
            </Col>
            <Col span="12">
                <FormItem label="联系电话">
                    <Input v-model="formData.contactPhone"/>
                </FormItem>
            </Col>
            <Col span="12">
                <FormItem label="电子邮箱" prop="channelAdminMail">
                    <Input v-model="formData.channelAdminMail"/>
                </FormItem>
            </Col>
            <Col span="24">
                <PlaceCascade
                    label="详细地址"
                    value="channelAddress"
                    detailValue="channelAdminAddress"
                    :form="formData"
                    :isDetailAddress="true"
                    :isDisabled="false"
                    :location="initLoadData"
                />
            </Col>
        </Row>
    </Form>
</template>

<script>
    import PlaceCascade from "_p/basic/pages/contract/common/PlaceCascade";
    import {getLocation} from "_p/basic/api/contract/common/common";

    export default {
        components: {
            PlaceCascade
        },
        props: {
            dataDict: {
                type: Object,
                required: true
            },
            formData: {
                type: Object,
                required: true
            }
        },
        data() {
            return {
                initLoadData: []
            };
        },
        mounted() {
            this.init();
        },
        methods: {
            init() {
                this.getInitData();
            },
            getInitData() {
                let param = {
                    level: "1",
                    upperCode: "1"
                };
                getLocation(param).then(res => {
                    if (res.code == "0000") {
                        res.data.forEach(item => {
                            // 表明是否是父节点
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        });
                    }
                    this.initLoadData.push(...res.data);
                });
            },
            loadData(item, callback) {
                item.loading = true;
                getLocation({upperCode: item.value}).then(res => {
                    if (res.code === "0000") {
                        res.data.forEach(function (item) {
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        });
                        item.children = res.data;
                        item.loading = false;
                        callback();
                    }
                });
            },
        }
    };
</script>

<style>
</style>
